﻿Public Class fFormasPago
    Dim daFormaPago As lbGlobalcom.dsCarteraTableAdapters.CAR_FORMASPAGOTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter

    Private Sub fFormasPago_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If DsCartera.CAR_FORMASPAGO.GetChanges IsNot Nothing Then
            CAR_FORMASPAGOBindingSource.EndEdit()
            If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Salvar Cambios", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                daFormaPago.Update(DsCartera.CAR_FORMASPAGO)
            End If
        End If

    End Sub
    Private Sub fFormasPago_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daFormaPago = New lbGlobalcom.dsCarteraTableAdapters.CAR_FORMASPAGOTableAdapter
            daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub btnCargaFP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargaFP.Click
        Try

            If DsCartera.CAR_FORMASPAGO.GetChanges IsNot Nothing Then
                CAR_FORMASPAGOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Salvar Cambios", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daFormaPago.Update(DsCartera.CAR_FORMASPAGO)
                End If
            End If
            daFormaPago.Fill(DsCartera.CAR_FORMASPAGO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAR_FORMASPAGOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAR_FORMASPAGOBindingNavigatorSaveItem.Click
        Try
            Validate()
            CAR_FORMASPAGOBindingSource.EndEdit()
            daFormaPago.Update(DsCartera.CAR_FORMASPAGO)
            MessageBox.Show("Se salvarón registros con exito", "salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                CAR_FORMASPAGOBindingSource.Remove(CAR_FORMASPAGOBindingSource.Current)
                daFormaPago.Update(DsCartera.CAR_FORMASPAGO)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
        
    End Sub

    Private Sub CAR_FORMASPAGODataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles CAR_FORMASPAGODataGridView.CellBeginEdit
        If e.ColumnIndex = 1 AndAlso CAR_FORMASPAGODataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
            dt = daClave.GetDataByIdClavePrimaria("CAR_FORMASPAGO")
            If dt.Count Then
                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                dr = dt.Rows(0)
                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                CAR_FORMASPAGODataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                Cons = Nothing
                CAR_FORMASPAGOBindingSource.EndEdit()
                daFormaPago.Update(DsCartera.CAR_FORMASPAGO)
            End If
        End If

    End Sub

    Private Sub CAR_FORMASPAGODataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles CAR_FORMASPAGODataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub CAR_FORMASPAGODataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles CAR_FORMASPAGODataGridView.UserDeletedRow
        Try
            daFormaPago.Update(DsCartera.CAR_FORMASPAGO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAR_FORMASPAGODataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles CAR_FORMASPAGODataGridView.UserDeletingRow
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
                e.Cancel = True
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub
End Class